package cn.iocoder.yudao.module.call.service.ivrlearn;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.call.controller.admin.ivrlearn.vo.*;
import cn.iocoder.yudao.module.call.dal.dataobject.ivrlearn.IvrLearnDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.call.dal.mysql.ivrlearn.IvrLearnMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.call.enums.ErrorCodeConstants.*;

/**
 * 大模型学习-未识别问题记录 Service 实现类
 *
 * @author 数创万维
 */
@Service
@Validated
public class IvrLearnServiceImpl implements IvrLearnService {

    @Resource
    private IvrLearnMapper ivrLearnMapper;

    @Override
    public Long createIvrLearn(IvrLearnSaveReqVO createReqVO) {
        // 插入
        IvrLearnDO ivrLearn = BeanUtils.toBean(createReqVO, IvrLearnDO.class);
        ivrLearnMapper.insert(ivrLearn);
        // 返回
        return ivrLearn.getId();
    }

    @Override
    public void updateIvrLearn(IvrLearnSaveReqVO updateReqVO) {
        // 校验存在
        validateIvrLearnExists(updateReqVO.getId());
        // 更新
        IvrLearnDO updateObj = BeanUtils.toBean(updateReqVO, IvrLearnDO.class);
        ivrLearnMapper.updateById(updateObj);
    }

    @Override
    public void deleteIvrLearn(Long id) {
        // 校验存在
        validateIvrLearnExists(id);
        // 删除
        ivrLearnMapper.deleteById(id);
    }

    private void validateIvrLearnExists(Long id) {
        if (ivrLearnMapper.selectById(id) == null) {
            throw exception(IVR_LEARN_NOT_EXISTS);
        }
    }

    @Override
    public IvrLearnDO getIvrLearn(Long id) {
        return ivrLearnMapper.selectById(id);
    }

    @Override
    public PageResult<IvrLearnDO> getIvrLearnPage(IvrLearnPageReqVO pageReqVO) {
        return ivrLearnMapper.selectPage(pageReqVO);
    }

}